package com.zh.config.rabbitmq;


import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.FanoutExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * Fanout
 */
@Configuration
public class FanoutRabbitConfig {
    /**
     *  创建三个队列 ：fanout.A   fanout.B  fanout.C
     *  将三个队列都绑定在交换机 fanoutExchange 上
     *  因为是扇型交换机, 路由键无需配置,配置也不起作用
     */

    @Bean
    public Queue createFanoutAQueue(){
        return new Queue("fanout.A",true);
    }

    @Bean
    public Queue createFanoutBQueue(){
        return new Queue("fanout.B",true);
    }
    @Bean
    public Queue createFanoutCQueue(){
        return new Queue("fanout.C",true);
    }

    /**
     * fanout 扇形交换机
     * @return
     */
    @Bean
    public FanoutExchange createFanoutExchange(){
        return new FanoutExchange("test-fanout-exchange",true,false);
    }

    /**
     * 绑定交换机和队列，因为时fanout交换机，没有路由的概念，所以不用绑定路由
     * @return
     */
    @Bean
    public Binding createBindingeA(){
        return BindingBuilder.bind(createFanoutAQueue()).to(createFanoutExchange());
    }
    @Bean
    public Binding createBindingeB(){
        return BindingBuilder.bind(createFanoutBQueue()).to(createFanoutExchange());
    }
    @Bean
    public Binding createBindingeC(){
        return BindingBuilder.bind(createFanoutCQueue()).to(createFanoutExchange());
    }

}
